package com.bitcat.firstapp.demo.intentdemo

import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.IntentCompat
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.bitcat.firstapp.R
import com.bitcat.firstapp.databinding.ActivitySecondBinding

class SecondActivity : AppCompatActivity() {

    private lateinit var binding: ActivitySecondBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        binding = ActivitySecondBinding.inflate(layoutInflater)
        setContentView(binding.root)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }



//        val name =  intent.getStringExtra("name")?:""
//        val age =  intent.getIntExtra("age",0)
//        val height =  intent.getDoubleExtra("height",0.0)
//        val isStudent =  intent.getBooleanExtra("is_student",false)
//        binding.contentTv.text = "name:$name,age:$age,height:$height,isStudent:$isStudent"

//        val person = intent.getSerializableExtra("person") as Person
//        binding.contentTv.text = "name:${person.name},age:${person.age}"


//        val person2 = intent.getParcelableExtra<Person2>("person")
//        binding.contentTv.text = "name:${person2?.name},age:${person2?.age}"

        val person2 = IntentCompat.getParcelableExtra(intent, "person", Person2::class.java)
        binding.contentTv.text = "name:${person2?.name},age:${person2?.age}"

    }

    //第二步：返回数据
    fun returnData(view: View) {
        val intent = Intent()
        intent.putExtra("name","zhangsan")
        setResult(RESULT_OK,intent)
        finish()
    }
}


